package model

import (
	_ "github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"gorm.io/gorm"
	"time"
)

type CustRecords struct {
	Id       int64     `gorm:"primary"`
	CustId   string    `gorm:"varchar(20);not null;unique"`
	SendTime time.Time `gorm:"datetime"`
	SendFlag uint8     `gorm:"tinyint(4)"`
}

// get records times in 30 days
func GetSendCnt(tx *gorm.DB, custId string) (int64, error) {
	var count int64
	tx.Raw("SELECT COUNT(*) AS count FROM records WHERE user_id = ? AND created_at >= ? GROUP BY DATE(created_at) ORDER BY date", custId, time.Now().AddDate(0, 0, -30)).First(&count)
	return 0, nil
}

// add record to user
func AddRecord(custId string) error {
	return nil
}
